package zoo.reviewboard.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;


import zoo.reviewboard.user.dao.ProductReviewBoardDao;
import zoo.reviewboard.user.domain.ProductReviewBoardCommand;
import zoo.util.FileUtil;

@Controller
public class ProductReviewBoardDeleteController {
	
	@Autowired
	private ProductReviewBoardDao rvDao;
	
	@ModelAttribute("ProductReviewBoardCommand")
	public ProductReviewBoardCommand formBacking(){
		return new ProductReviewBoardCommand();
	}
	  
	@RequestMapping(value="/main/reviewDelete.do")
	public String submit(@ModelAttribute("p_code")int p_code,
							@ModelAttribute("rv_num")int rv_num
						 ){
		
		
		String formView2 = "redirect:/main/detailPro.do?p_code="+p_code;
		
		ProductReviewBoardCommand command = rvDao.selectReview(rv_num);
		
		rvDao.deleteReview(rv_num);
			
		if(command.getPr_image() != null){
			FileUtil.removeFile(command.getPr_image());
		}

		return formView2; 
	}
}
